package com.example.recruitment_website.controller;

import com.example.recruitment_website.domain.Collection;
import com.example.recruitment_website.dto.HeadlinesBriefDto;
import com.example.recruitment_website.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("Collection")
public class CollectionController {
    @Autowired
    CollectionService collectionService;

    @GetMapping("/findCollectionByUserId")
    public HashMap findCollectionByUserId(int id){
        List<Collection> testList = collectionService.findAllCollection(id);
        HashMap<String,Object> map = new HashMap<>();
        map.put("data",testList);
        map.put("msg","请求成功");
        map.put("code",0);
        return map;
    }

    @GetMapping("/addCollection")
    public HashMap addCollection(int id,int userId){
        collectionService.addCollection(id,userId);
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","添加成功");
        map.put("code",1);
        return map;
    }

    @GetMapping("/delCollection")
    public HashMap delCollection(int id,int userId){
        int state=collectionService.delCollection(id,userId);
        HashMap<String,Object> map = new HashMap<>();
        if (state == 0){
            map.put("msg","删除失败，请检查输入参数");
            map.put("code",0);
        }else {
            map.put("msg","删除成功");
            map.put("code",1);
        }


        return map;
    }




}
